package org.jeecg.modules.flow.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.flow.entity.ActRuTask;
import org.jeecg.modules.flow.query.TaskQuery;
import org.jeecg.modules.flow.service.IActRuTaskService;
import org.jeecg.modules.flow.vo.TaskVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: ru_task
 * @Author: jeecg-boot
 * @Date: 2021-12-28
 * @Version: V1.0
 */
@Api(tags = "运行任务API")
@RestController
@RequestMapping("/flow/actRuTask")
@Slf4j
public class ActRuTaskController extends JeecgController<ActRuTask, IActRuTaskService> {
	@Autowired
	private IActRuTaskService actRuTaskService;

	/**
	 * 分页列表查询
	 *
	 * @param actRuTask
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value = "ru_task-分页列表查询", notes = "ru_task-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(ActRuTask actRuTask,
								   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
								   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<ActRuTask> queryWrapper = QueryGenerator.initQueryWrapper(actRuTask, req.getParameterMap());
		Page<ActRuTask> page = new Page<>(pageNo, pageSize);
		IPage<ActRuTask> pageList = actRuTaskService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
	 * 查询用户的所有任务,包括代办任务、候选组任务、角色任务
	 *
	 * @return 返回当前用户的任务列表
	 */
	@ApiOperation(value = "查询用户待办任务", notes = "")
	@GetMapping("/findTasks")
	public Result<Page<TaskVo>> findTasks(TaskQuery query,
										  @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
										  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
		Page<TaskVo> tasks = actRuTaskService.findTasks(query, pageNo, pageSize);
		return Result.OK(tasks);
	}

}
